# -*- coding: utf-8 -*-
import win32gui as ControlUI
import win32con as IconUI
import win32clipboard as Clipboard

NextChildNamelist=[]

def Name(QQgroup,QQname):
    ChatWindowName=str(QQgroup)
    QRobotName=str(QQname)
    return ChatWindowName,QRobotName

def SendMessage(ChatWindow, ChatWindowMessage):
    Clipboard.OpenClipboard()
    Clipboard.EmptyClipboard()
    Clipboard.SetClipboardData(IconUI.CF_UNICODETEXT, ChatWindowMessage)
    Clipboard.CloseClipboard()
    SendOut=ControlUI.FindWindow(None, ChatWindow)
    if SendOut!= 0:
        ControlUI.SendMessage(SendOut, 770, 0, 0)
        ControlUI.SendMessage(SendOut, IconUI .WM_KEYDOWN, IconUI .VK_RETURN, 0)
        print('发送成功')
    else:
        print('失败')

def PrintChildInformation(farther, retract_level=0):

    def Capturelevel(retract_level):
        for i in range(retract_level):
            print("\t", end="")

    NextChild = farther.GetFirstChildControl()
    Capturelevel(retract_level)
    try:
        print(NextChild.Name)
    except:
        pass

    if NextChild is not None:
        ChildSon = NextChild.GetFirstChildControl()
        if ChildSon:
            PrintChildInformation(NextChild, retract_level + 1)

    while NextChild:
        NextChild = NextChild.GetNextSiblingControl()
        Capturelevel(retract_level)
        try:
            print(NextChild.Name)
            if ':' in NextChild.Name :
                NextChildNamelist.append(NextChild.Name)

        except :
             pass

        if NextChild is not None:
            ChildSon = NextChild.GetFirstChildControl()
            if ChildSon:
                PrintChildInformation(NextChild, retract_level + 1)

